package com.vrv.mysqlback;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

/**
 * @author Bang
 * @ClassName: ErrorStreamCallable
 * @Desc: TODO
 * @Date: 2021/08/27 16:23
 * @Version: 1.0
 * @Modified By:
 */
public class HandlerInputStreamCallable implements Callable<List<String>> {

    private List<String> msg = new ArrayList<String>();


    /**
     * Computes a result, or throws an exception if unable to do so.
     *
     * @return computed result
     * @throws Exception if unable to compute a result
     */
    @Override
    public List<String> call() throws Exception {
        String line;
        try {
            while ((line = bReader.readLine()) != null) {
                msg.add(line);
            }
            bReader.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return msg;
    }

    BufferedReader bReader = null;

    public HandlerInputStreamCallable(InputStream is) {
        try {
            bReader = new BufferedReader(new InputStreamReader(new BufferedInputStream(is), StandardCharsets.UTF_8));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }


}
